{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def toHex(self, num):\n",
    "        \"\"\"\n",
    "        :type num: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        if num == 0:\n",
    "            return '0'\n",
    "        \n",
    "        hex = '0123456789abcdef'\n",
    "        max = 16**8\n",
    "        \n",
    "        if num < 0:\n",
    "            num = max + num\n",
    "        \n",
    "        s = ''\n",
    "        while num > 0:\n",
    "            s = hex[num % 16] + s\n",
    "            num = num // 16\n",
    "        \n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ffffffff'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.toHex(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
